<?php
class TutorApprove extends Controller {
	var $msg = '';
	function TutorApprove()
	{
		parent::Controller();
	}

	function index()
	{
	 	if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
		$data['form_status'] = 'add';
		$this->load->model('TutorModel');
		$data['studentlList'] = $this->TutorModel->getAllFromFrontEnd();
		$this->load->view('header');
		$this->load->view('tutor-approve-form', $data);
		if($this->msg != null && count($this->msg) > 0)
			$msg = array('msg' => $this->msg);
		else
			$msg = null;
		$this->load->view('footer', $msg);
	}
	
	function save()
	{
		if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
	    $this->load->model('TutorModel');
	    $stuID = $this->input->post('txtDel');
	    
	    for($i = 0; $i < count($stuID); $i++) {
	    	$data = array();
	    	$data['tutor_id'] = $stuID[$i];
    		$data['status'] = 'approve';
    		$this->TutorModel->approve($data);
	    }
	    $this->msg = "บันทึกข้อมูลเรียบร้อย";
	    $this->index();
	}
	
	function ignore()
	{
		if ($this->session->userdata('logged_in') != TRUE)
	    {
	        redirect('login/index');
	    }
	    $this->load->model('TutorModel');
	    $stuID = $this->input->post('txtDel');
	    
	    for($i = 0; $i < count($stuID); $i++) {
    		$this->TutorModel->delete($stuID[$i]);
	    }
	    $this->msg = "บันทึกข้อมูลเรียบร้อย";
	    $this->index();
	}
}

?>